﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SqlCon;
using System.Runtime.InteropServices;

namespace yfxt
{
    public partial class gl_yprkd_zuo : Form
    {
        public gl_yprkd_zuo()
        {
            InitializeComponent();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void gl_yprkd_zuo_Load(object sender, EventArgs e)
        {
            dataGridView1.AllowUserToResizeRows = false;                     //禁止用鼠标调整datagridView单元格的大小。
            dataGridView1.AllowUserToResizeColumns = false;
            foreach (DataGridViewColumn c in dataGridView1.Columns)        //禁止对datagridView列进行排序
            {
                c.SortMode = DataGridViewColumnSortMode.NotSortable;
            }

            //string rukudanhao = ((gl_yprk)this.Owner).rukudanhao;
            string rukudanhao = gl_yprk.rukudanhao;
            DataTable dt = new DataTable();
            DataTable dt2 = new DataTable();

            //显示No.100001
            label6.Text = rukudanhao;

            //显示入库日期、备注、入库员
            string comStr = "select t.rkrq,t.rkbz,t1.ygxm from YF_RK01 t,GY_YGDM t1 where t.rkdh='" + rukudanhao + "' and t.czgh=t1.ygbh";
            dt2.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null));
            textBox2.Text = Convert.ToDateTime(dt2.Rows[0][0]).ToString("yyyy-MM-dd").Replace('-', '.');
            textBox3.Text=dt2.Rows[0][1].ToString();
            textBox4.Text = dt2.Rows[0][2].ToString();

            //显示合计
            comStr = "select sum(lsje) from yf_rk02 where rkdh='" + rukudanhao + "'";
            string total_lsje = (SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null)).ToString();
            textBox6.Text = total_lsje;

            //显示datagridView1的            
            comStr = "select t1.ypmc,t.ypgg,t.yfdw,t2.cdqc,t.lsjg,t.rksl,t.lsje,t.ypph,t.ypxq,t3.fsmc from YF_RK02 t,yk_typk t1,YK_CDDZ t2,YF_RKFS t3 " +
                "where t.rkdh='" + rukudanhao + "' and t.ypxh=t1.ypxh and t2.ypcd=t.ypcd and t3.yfsb=t.yfsb and t3.rkfs=t.rkfs";
            dt.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dataGridView1.Rows.Add(1);                

                 for (int j = 0; j < 9; j++)
                 {
                    if (j == 8)
                    {
                        dataGridView1.Rows[i].Cells[j].Value = Convert.ToDateTime(dt.Rows[i][j]).ToString("yyyy-MM-dd").Replace('-', '.');
                    }
                    else
                    {
                        dataGridView1.Rows[i].Cells[j].Value = dt.Rows[i][j].ToString();
                    }                    
			    }
            }

            //显示入库方式
            textBox1.Text = dt.Rows[0][9].ToString();
        }

        #region TextBox1.text 不能被选中
        private void textBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.textBox1.SelectionLength > 0)
            {
                this.textBox1.SelectionStart = this.textBox1.TextLength;
                this.textBox1.SelectionLength = 0;
            }
        }
        #endregion

        #region  隐藏TextBox1光标闪烁
        [DllImport("user32.dll", EntryPoint = "HideCaret")]
        public static extern bool HideCaret(IntPtr hWnd);
        private void textBox1_MouseDown(object sender, MouseEventArgs e)
        {
            HideCaret(((TextBox)sender).Handle);
        }
        #endregion

        private void button3_Click(object sender, EventArgs e)
        {
            //gl_yprk_rpt rpt = new gl_yprk_rpt();
            //rpt.Show();
        }
    }
}
